<?php

namespace IDock\Insurance\DAJIA\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends CommonResponse
{
    /**
     * @var VehicleModelPrinter $printer
     */
    public $printer;

    public function printerInit() :Response
    {
        $energyType = [
            'D1' => 'E11',
            'D2' => 'E12',
            'D3' => 'E16',
            'D4' => 'E15',
            'D5' => 'E20',
            'D6' => 'E13',
            'D7' => 'E21',
            'D8' => 'E22',
            'D9' => 'E17',
            'D11' => 'E00',
            'D12' => 'E04',
            'D14' => 'E19',
            'D15' => 'E10',
            '' => 'E10',
        ];
        $vehicleModelPrinter = new VehicleModelPrinter();
        $modelList =  [];
        foreach ($this->getData()['result'] as $value){
            $modelList[$value['vehicleId']] = $value;
        }
        $modelList = array_values($modelList);
        foreach ($modelList as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['vehicleId'] ?? '';
            $vehiclePrinter->brandName = $datum['brandName'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['vehicleExhaust'] ?? '';
            $vehicleType = $datum['vehicleType'] ?? 'I0';
            if ($vehicleType == '合资车') {
                $vehiclePrinter->vehicleImport = 'I2';
            } elseif ($vehicleType == '国产车') {
                $vehiclePrinter->vehicleImport = 'I1';
            } elseif ($vehicleType == '进口车') {
                $vehiclePrinter->vehicleImport = 'I3';
            }

            $vehiclePrinter->vehicleName = $datum['vehicleName'] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['vehiclePrice'] ?? '';
            $vehiclePrinter->vehiclePriceTax = $datum['vehiclePriceTax'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['vehicleSeat'] ?? '';
            $vehiclePrinter->remark = $datum['remark'] ?? '';
            $vehiclePrinter->familyName = $datum['familyName'] ?? '';
            $vehiclePrinter->power = $datum['power'] ?? '';
            $vehiclePrinter->vehicleYear = $datum['yearPattern'] ?? '';
            $vehiclePrinter->vehicleTonnage = $datum['vehicleTonnage'] ?? '';
            $vehiclePrinter->wholeWeight = $datum['qualityMax'] ?? '';
            $vehiclePrinter->energyTypeCode = $energyType[$datum['powerTypeCode'] ?? ''];
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode];
            //$vehiclePrinter->item = $datum;
            if($datum['powerTypeCode'] == 'D6' || $datum['powerTypeCode'] == 'D12'){
                $vehiclePrinter->isNewEnergy = '1';
            }

            $vehicleModelPrinter->setModelList($vehiclePrinter);
        }

        $this->printer = $vehicleModelPrinter;

        return $this;
    }
}
